package com.kezesong.leasing.controller.admin;


import com.kezesong.leasing.common.ResponseResult;
import com.kezesong.leasing.controller.BaseController;
import com.kezesong.leasing.controller.request.AddShopInfoReqBody;
import com.kezesong.leasing.entity.ShopInfoEntity;
import com.kezesong.leasing.service.ShopInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class ShopManagerController extends BaseController {

    @Autowired
    private ShopInfoService shopInfoService;

    @PostMapping("/getShopList.do")
    @ApiOperation(value = "getShopList", notes = "管理员获取商铺所有列表")
    public ResponseResult<List<ShopInfoEntity>> getShopList(){
        List<ShopInfoEntity> shopInfoList = shopInfoService.getShopInfoList();
        ResponseResult<List<ShopInfoEntity>> listResponseResult = buildSucessResponse(shopInfoList);
        return listResponseResult;
    }

    @PostMapping("/addShop.do")
    @ApiOperation(value = "addShopInfo", notes = "添加商铺 ")
    public ResponseResult<Integer> addShopInfo(@Validated @RequestBody AddShopInfoReqBody addShopInfoReqBody){
        ShopInfoEntity shopInfoEntity = new ShopInfoEntity();
        BeanUtils.copyProperties(addShopInfoReqBody, shopInfoEntity);
        int result = shopInfoService.addShopInfo(shopInfoEntity);
        ResponseResult<Integer> integerResponseResult = buildSucessResponse(result);
        return integerResponseResult;

    }
}
